﻿using System;
using NUnit.Framework;
using StackOverflowClient;
using System.Net;

namespace StackOverflowClientUnitTests
{
    [TestFixture]
    public class ParserUnitTests
    {
    	[Test]
    	public void GrabStreamFromInternetOverHttp()
    	{
    		string result = HttpWebRequestExtension.GetStringFromURL("http://stackoverflow.com/users/11361/dror-helper", null);
    		Assert.IsNotEmpty(result);
    		Console.WriteLine(result);
    		UserDescriptor user = Parser.Parse(result);
    		
    		Assert.AreEqual("Dror Helper", user.Name);
            //Assert.AreEqual("http://www.gravatar.com/avatar/db8b562e21f8f67bd924c3d6bcc60f4c?s=128&d=identicon&r=PG", user.Image);
    	}
    	
        [Test]
        public void TestParsingFromFile()
        {
            string s = System.IO.File.ReadAllText(@".\sample1.txt");
            Console.WriteLine(s);

            UserDescriptor user = Parser.Parse(s);
            

            Assert.AreEqual("Dror Helper", user.Name);
            Assert.AreEqual(602, user.Reputation);
            Assert.AreEqual("http://www.gravatar.com/avatar/db8b562e21f8f67bd924c3d6bcc60f4c?s=128&d=identicon&r=PG", user.Image);
        }
        
        [Test]
        public void TestParsingFromFile2()
        {
            string s = System.IO.File.ReadAllText(@".\sample2.txt");
            Console.WriteLine(s);

            UserDescriptor user = Parser.Parse(s);
            

            Assert.AreEqual("Martin York", user.Name);
            Assert.AreEqual(2171, user.Reputation);
            Assert.AreEqual("http://www.gravatar.com/avatar/f81482fa92712e3e58c39ad6f8580313?s=128&d=identicon&r=PG", user.Image);
        }
    }
}